package com.ragdollcat.thirdaicodegenerate.ai.strategy;

import com.ragdollcat.thirdaicodegenerate.exception.ErrorCode;
import com.ragdollcat.thirdaicodegenerate.exception.ThrowUtils;
import com.ragdollcat.thirdaicodegenerate.model.entity.User;
import com.ragdollcat.thirdaicodegenerate.service.ChatHistoryService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;

/**
 * 对话并生成文件 结果处理策略类
 */
@Component
public class FluxHandlerStrategy {


    @Resource
    private CommonFluxHandler commonFluxHandler;

    @Resource
    private ProjectFluxHandler projectFluxHandler;


    public Flux<String> fluxHandler(String bizType,
                                    Flux<String> flux,
                                    ChatHistoryService chatHistoryService,
                                    Long appId,
                                    User user,
                                    Integer version) {
        switch (bizType) {
            case "html", "multi_file" -> {
                return commonFluxHandler.handlerCommon(flux, chatHistoryService, appId, user,version);
            }
            case "vue_project" -> {
                return projectFluxHandler.handlerProject(flux, chatHistoryService, appId, user,version);
            }
            default -> ThrowUtils.throwIf(true, ErrorCode.OPERATION_ERROR, "非法的生成项目类型！");
        }
        return null;

    }
}
